﻿
import flash.geom.Point;
import mx.utils.Delegate;
import mx.transitions.Tween;
import mx.transitions.easing.*; 
import cn.eminia.A2.utils.uTween;
import gs.*; 

/**
 * ...
 * @author wangjun
 */
class cn.eminia.A2.ui.Pannel  extends MovieClip
{
	public var onOpen:Function;
	public var onOpenInit:Function;
	public var onOpenEnd:Function;
	
	public var onClose:Function;
	public var onCloseInit:Function;
	public var onCloseEnd:Function;
	
	public var openStyle:String;
	
	static public var BezierStyle:String = 'bezier';
	
	public var sttPos:Point;
	public var endPos:Point;
	
	public var regPoint:Point;
	public function Pannel() 
	{
		this._visible = false;
	}
	public function open(doTw:Boolean, callBack:Function) {
		
		var _doTw = (doTw == null)?true:doTw;
		if (onOpenInit != null && onOpen.constructor==Function)  	onOpenInit();  
		if (onOpenEnd != null) 	{ callBack = onOpenEnd }
		
			trace("["+getTimer()+"]"+"!! openStyle = "+openStyle)
		if (_doTw) {
			if (this.openStyle == "bezier") {
				//trace("regPoint = "+ regPoint )
				if (regPoint == null) throw new Error('cn.eminia.A2.ui.Pannel::open 缺少 regPoint');
				if (sttPos == null) throw new Error('cn.eminia.A2.ui.Pannel::open 缺少 sttPos');
				uTween.pannel_bezier(this, [0, 1], { onComplete:callBack,sttPos:sttPos}, regPoint);
			}else{
				uTween.pannel(this, [0, 1], { onComplete:callBack }, regPoint);
			}
		}else {
			uTween.pannel_NoBlur(this, [0, 1], {onComplete:callBack},regPoint);
		}
		
		if ( onOpen!=null && onOpen.constructor==Function) 			onOpen();
	}
	public function close(doTw:Boolean, callBack:Function) {
		
		var _doTw = (doTw == null)?true:doTw;		
		if (onCloseInit != null) 	{ onCloseInit(); }
		if (onCloseEnd != null) 	{ callBack = onCloseEnd }
		
		if (_doTw) {
			if (this.openStyle == "bezier") {
				//trace("regPoint = "+ regPoint )
				if (regPoint == null) throw new Error('cn.eminia.A2.ui.Pannel::open 缺少 regPoint');
				if (endPos == null) throw new Error('cn.eminia.A2.ui.Pannel::open 缺少 sttPos');
				uTween.pannel_bezier(this, [1, 0], { onComplete:callBack,endPos:endPos}, regPoint);
			}else 
			{
				uTween.pannel(this, [1, 0], {onComplete:callBack},regPoint); 
			}
		}else {
			uTween.pannel_NoBlur(this, [1, 0], {onComplete:callBack},regPoint);
		}
		
		if ( onClose!=null && onClose.constructor==Function) onClose();
	}
	public function moveTo(x, y) {
		this._x = x;
		this._y = y;		
	}	
}